package net2;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.SocketAddress;

public class UdpEchoClient {
    private static final SocketAddress address =
            new InetSocketAddress("127.0.0.1", 8888);

    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket();
        byte[] bytes = "miss Queena everyday".getBytes();
        DatagramPacket packet = new DatagramPacket(bytes, bytes.length, address);
        socket.send(packet);
        System.out.println("客户端数据已发送...");
        System.out.println("等待服务器响应...");
        byte[] response = new byte[516];
        DatagramPacket resp = new DatagramPacket(response, response.length);
        socket.receive(resp);
        System.out.println("服务器响应内容：" + new String(resp.getData()));
    }
}
